<template>
  <div class="micro-page">
    <div class="search-box">
      <el-button type="primary" @click="showPageTitle('create')">新建页面</el-button>
      <div class="search-item">
        <el-input v-model="KeyMicroPage" placeholder="请输入微页面名称" style="width:200px;" />
        <el-button type="primary">搜索</el-button>
      </div>
    </div>
    <el-table
      :data="microPageTableData"
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <el-table-column prop="pageName" label="页面名称">
        <template slot-scope="scope">
          <span>{{ scope.row.pageName }}</span>
          <el-tag v-if="scope.row.home" effect="dark" style="margin-left:10px;">店铺主页</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" align="center" />
      <el-table-column label="操作" align="right">
        <template slot-scope="scope">
          <el-button type="text" @click="goCreatePage(scope.row.id)">装修</el-button>
          <el-button type="text" @click="showPageTitle('edit')">修改名称</el-button>
          <el-button type="text" @click="homeSet(scope.$index)">设为主页</el-button>
          <el-button type="text" :disabled="scope.row.home" @click="removePage(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="dialogTitle" :visible.sync="pageTitleDialog" width="500px">
      <div>
        <span>页面名称:</span>
        <el-input v-model="pageTitle" style="width:60%"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="pageTitleDialog = false">取 消</el-button>
        <el-button v-if="!editStatus" type="primary" @click="goCreatePage()">保存，去装修</el-button>
        <el-button v-if="editStatus" type="primary" @click="pageTitleDialog = false">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      KeyMicroPage: '',
      microPageTableData: [
        {
          id: '1',
          pageName: '',
          createTime: '2019-06-02 13:30',
          home: true
        },
        {
          id: '2',
          pageName: '云尚',
          createTime: '2019-06-03 13:30',
          home: false
        }
      ],
      pageTitleDialog: false,
      pageTitle: '',
      editStatus: false,
      dialogTitle: '新建页面'
    }
  },
  methods: {
    showPageTitle(status) {
      if (status === 'create') {
        this.editStatus = false
        this.dialogTitle = '新建页面'
        this.pageTitleDialog = true
      } else {
        this.editStatus = true
        this.dialogTitle = '修改页面'
        this.pageTitleDialog = true
      }
    },
    goCreatePage(e, id) {
      this.$router.push({ name: 'Decoratepage', query: { 'pageNameId': id } })
    },
    // 设置主页
    homeSet(index) {
      this.microPageTableData.map(item => {
        item.home = false
      })
      this.microPageTableData[index].home = true
    },
    // 删除页面数据
    removePage(id) {
      this.$confirm('删除后将不可恢复，确认删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 删除
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.micro-page {
  .search-box {
    margin-bottom: 20px;
    .search-item {
      float: right;
    }
  }
  .class-title {
    box-sizing: border-box;
    width: 100%;
    height: 100px;
    margin-bottom: 24px;
    padding: 20px 24px;
    background: #f5f7fa;
    .title {
      margin-bottom: 10px;
      color: #353535;
      font-weight: 700;
      font-size: 20px;
    }
    .tip {
      display: inline-block;
      margin-right: 30px;
      font-size: 14px;
      line-height: 22px;
      .label {
        margin-right: 20px;
        color: #888;
      }
      .content {
        color: #353535;
      }
    }
  }
}
</style>
